import { TagColors } from '@/utils';
import type { ProColumns, ProFormColumnsType } from '@ant-design/pro-components';
import { Tag } from 'antd';
export const TABLE_COLUMNS: ProColumns<any>[] = [
  {
    title: '菜单名称',
    dataIndex: 'title',
    hideInSearch: true,
  },
  {
    title: '排序',
    dataIndex: 'menuSort',
    hideInSearch: true,
  },
  {
    title: '类型',
    dataIndex: 'type',
    hideInSearch: true,
    render: (_, row) => {
      // 菜单类型 0-目录 1-菜单 2-按钮
      const Obj: any = {
        0: '目录',
        1: '菜单',
        2: '按钮',
      };
      try {
        return <Tag color={TagColors[row.type]}>{Obj[row.type]}</Tag>;
      } catch (error) {
        return '-';
      }
    },
  },
  {
    title: '路由地址',
    dataIndex: 'path',
    hideInSearch: true,
  },
  {
    title: '权限',
    dataIndex: 'permission',
    hideInSearch: true,
  },
  {
    title: '图标',
    dataIndex: 'icon',
    hideInSearch: true,
  },
];
export const FORM_COLUMNS: ProFormColumnsType<any>[] = [
  {
    title: '菜单名称',
    dataIndex: 'title',
    formItemProps: {
      rules: [{ required: true }],
    },

    colProps: {
      xs: 12,
      md: 12,
    },
  },
  {
    title: '排序',
    dataIndex: 'menuSort',
    valueType: 'digit',
    formItemProps: {
      rules: [{ required: false }],
    },
    initialValue: 10,

    colProps: {
      xs: 12,
      md: 12,
    },
  },
  {
    valueType: 'dependency',
    name: ['type'],
    columns: ({ type }) => {
      return type === 2
        ? [
            {
              title: '权限',
              dataIndex: 'permission',
              formItemProps: {
                rules: [{ required: false }],
              },

              colProps: {
                xs: 12,
                md: 12,
              },
            },
          ]
        : [
            {
              title: '路由地址',
              dataIndex: 'path',
              hideInForm: false,
              formItemProps: {
                rules: [{ required: false }],
              },
              colProps: {
                xs: 12,
                md: 12,
              },
            },
            {
              title: '图标',
              dataIndex: 'icon',
              formItemProps: {
                rules: [{ required: false }],
              },

              colProps: {
                xs: 12,
                md: 12,
              },
            },
            {
              title: '是否缓存',
              dataIndex: 'cache',
              valueType: 'radio',
              formItemProps: {
                rules: [{ required: false }],
              },
              initialValue: false,
              fieldProps: {
                options: [
                  { label: '是', value: true },
                  { label: '否', value: false },
                ],
              },
              colProps: {
                xs: 12,
                md: 12,
              },
            },
            {
              title: '是否显示',
              dataIndex: 'hidden',
              formItemProps: {
                rules: [{ required: false }],
              },
              initialValue: true,
              fieldProps: {
                options: [
                  { label: '是', value: true },
                  { label: '否', value: false },
                ],
              },
              valueType: 'radio',

              colProps: {
                xs: 12,
                md: 12,
              },
            },
            {
              title: '组件路径',
              dataIndex: 'component',
              formItemProps: {
                rules: [{ required: false }],
              },

              colProps: {
                xs: 12,
                md: 12,
              },
            },
            {
              title: '是否iframe',
              dataIndex: 'iframe',
              valueType: 'radio',
              initialValue: false,
              formItemProps: {
                rules: [{ required: false }],
              },
              fieldProps: {
                options: [
                  { label: '是', value: true },
                  { label: '否', value: false },
                ],
              },

              colProps: {
                xs: 12,
                md: 12,
              },
            },

            {
              title: '组件名称',
              dataIndex: 'name',
              formItemProps: {
                rules: [{ required: false }],
              },

              colProps: {
                xs: 12,
                md: 12,
              },
            },
          ];
    },
  },

  {
    title: '描述',
    dataIndex: 'description',
    valueType: 'textarea',
    formItemProps: {
      rules: [{ required: false }],
    },
    colProps: {
      xs: 12,
      md: 12,
    },
  },
];
